﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DevExpress.UserSkins;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using System.Threading;
using Agile.Core;

namespace Agile.Develop
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //注册全局异常捕捉
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans");
            BonusSkins.Register();
            SkinManager.EnableFormSkins();
            Mailslot.NamedPipe.IsDebug = true;
            Agile.Core.WaitFormEx.Show("正在启动系统,请稍后 ...");
            Application.Run(new ParentForm());
        }
        private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Agile.Core.WaitFormEx.Close();
            Exception ex = (Exception)e.ExceptionObject;
            AgileDebug.Message(DebugType.未知异常, "系统发生异常", ex).Show("系统发生未知异常，详情参考日志。", "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }
        private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
        {
            Agile.Core.WaitFormEx.Close();
            AgileDebug.Message(DebugType.未知异常, "系统发生异常", t.Exception).Show("系统发生未知异常，详情参考日志。", "程序异常", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }
    }
}
